package cn.gzmli.dtt.common.controll;

import cn.gzmli.dtt.common.entity.PageInfo;
import cn.gzmli.dtt.common.utils.Constant;
import cn.gzmli.dtt.common.entity.Result;
import cn.gzmli.dtt.common.service.log.OperatorLogService;
import com.xiaoleilu.hutool.util.StrUtil;
import jdk.nashorn.internal.ir.annotations.Ignore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Descript 系统操作日志
 * @Author xsx
 * @Date 2018/3/21
 */
@Controller
@RequestMapping("/system/log/operator")
@ResponseBody
@Ignore
public class OperatorLogController {
    @Autowired
    private OperatorLogService operatorLogService;

    @RequestMapping("/list")
    public Result list() throws Exception {
        return new Result(Constant.SUCCESS, "获取系统操作日志列表成功", this.operatorLogService.getAll());
    }

    @RequestMapping("/listByCondition")
    public Result listByCondition(HttpServletRequest request, PageInfo pageInfo) throws Exception {
        Map<String, Object> condition = new HashMap<>();
        if (StrUtil.isNotBlank(request.getParameter("name"))){
            condition.put(" AND name LIKE ?", "%"+request.getParameter("name")+"%");
        }
        if (StrUtil.isNotBlank(request.getParameter("loginName"))){
            condition.put(" AND loginName LIKE ?", "%"+request.getParameter("loginName")+"%");
        }
        if (StrUtil.isNotBlank(request.getParameter("userName"))){
            condition.put(" AND userName LIKE ?", "%"+request.getParameter("userName")+"%");
        }
        if (StrUtil.isNotBlank(request.getParameter("url"))){
            condition.put(" AND url LIKE ?", "%"+request.getParameter("url")+"%");
        }
        List<Map<String, Object>> data = this.operatorLogService.getByCondition(condition, pageInfo);
        return new Result(Constant.SUCCESS, "获取系统操作日志列表成功", data, pageInfo);
    }
}
